package com.atguigu.gmall.common.config.minio;

import com.atguigu.gmall.common.config.minio.properties.AppMinioProperties;
import io.minio.MinioClient;
import io.minio.errors.InvalidEndpointException;
import io.minio.errors.InvalidPortException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author lfy
 * @Description
 * @create 2022-11-01 8:44
 */
//@EnableConfigurationProperties
//1、让整个属性绑定做完
//2、把 AppMinioProperties 放到ioc容器中
@EnableConfigurationProperties(AppMinioProperties.class)
@Configuration
public class AppMinioAutoConfiguration {



    @Autowired
    AppMinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() throws InvalidPortException, InvalidEndpointException {
        MinioClient minioClient = new MinioClient(
                minioProperties.getEndpoint(),
                minioProperties.getAccessKey(),
                minioProperties.getSecretKey());

        return minioClient;
    }
}
